﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity.Car_Rental;

namespace Data.Car_Rental
{
    public class HelperCenterRepository : Car_RentalRepositoryBase, IHelperCenterRepository
    {
        #region IRepository<HelperCenter> 成员

        public void Update(Entity.Car_Rental.HelperCenter entity)
        {
            base.UpdateEntity(entity);
        }

        public void Update(IList<Entity.Car_Rental.HelperCenter> list)
        {
            base.UpdateEntity(list.Cast<Entity.EntityBase>().ToList());
        }

        public void Insert(Entity.Car_Rental.HelperCenter entity)
        {
            base.InsertEntity(entity);
        }

        public void Insert(IList<Entity.Car_Rental.HelperCenter> list)
        {
            base.InsertEntity(list.Cast<Entity.EntityBase>().ToList());
        }

        public Entity.Car_Rental.HelperCenter InsertGetIDENTITY(Entity.Car_Rental.HelperCenter entity)
        {
            base.InsertEntity(entity);
            return this.Find(entity.PrimaryKey);
        }

        public void Delete(Entity.Car_Rental.HelperCenter entity)
        {
            base.DeleteEntity(entity);
        }

        public void Delete(IList<Entity.Car_Rental.HelperCenter> list)
        {
            base.DeleteEntity(list.Cast<Entity.EntityBase>().ToList());
        }

        public IQueryable<Entity.Car_Rental.HelperCenter> GetModel()
        {
            return base.GetEntities<HelperCenter>().Select(i => new HelperCenter_Ext
            {
                CreateDate = i.CreateDate,
                HelpCategoryID = i.HelpCategoryID,
                HelpID = i.HelpID,
                Info = i.Info,
                Status = i.Status,
                Title = i.Title,
                UpdateDate = i.UpdateDate,
            });
        }

        public Entity.Car_Rental.HelperCenter Find(params object[] keyValues)
        {
            return base.Find<HelperCenter>(keyValues);
        }

        #endregion

        #region IHelperCenterRepository 成员

        public IQueryable<HelperCenter> GetDetailModel()
        {
            var linq = from i in this.GetModel()
                       join data2 in new HelperCenterCategoryRepository().GetModel() on i.HelpCategoryID equals data2.HelpCategoryID
                       select new HelperCenter_Ext
                       {
                           CreateDate = i.CreateDate,
                           HelpCategoryID = i.HelpCategoryID,
                           HelpID = i.HelpID,
                           Info = i.Info,
                           Status = i.Status,
                           Title = i.Title,
                           UpdateDate = i.UpdateDate,
                           HelperCenterCategory_Extend = data2,
                       };
            return linq;
        }

        #endregion
    }
}
